package Learn;

import org.w3c.dom.ls.LSInput;

import java.util.Random;
import java.util.Scanner;

public class Learn {
    public static void main (String[] args) {
        Scanner p = new Scanner (System.in);
        System.out.println ("请输入一个数字：");
        int num = p.nextInt ();
        System.out.println ("偶数位是：");
        for (int i = 30; i >= 0; i -= 2) {
            System.out.print ((num >> i) & 1);
            System.out.print (" ");
        }
        System.out.println ();
        System.out.println ("奇数位是：");
        for (int i = 31; i >= 1; i -= 2) {
            System.out.print ((num >> i) & 1);
            System.out.print (" ");
        }

    }

    public static void main8 (String[] args) {
        int i = 3;
        Scanner p = new Scanner (System.in);
        String rcode = "88888888";
        while (i > 0) {
            System.out.println ("请输入密码：");
            String code = p.nextLine ();
            if (code.equals (rcode)) {
                System.out.println ("恭喜答对！");
                break;
            } else {
                System.out.println ("抱歉答错");
                i--;
                System.out.printf ("还有%d次机会", i);
            }

        }
        if (i == 0) System.out.println ("抱歉答错，次数已经用完");
    }

    public static void main7 (String[] args) {
        Scanner p = new Scanner (System.in);
        int i = p.nextInt ();
        int j = p.nextInt ();
        int t = 0;
        while (i % j != 0) {
            t = i % j;
            i = j;
            j = t;
        }
        System.out.println ("最大公约数是：");
        System.out.println (j);
    }


    public static void main6 (String[] args) {
        Scanner p = new Scanner (System.in);
        int i = p.nextInt ();
        while (i > 10) {
            System.out.println (i % 10);
            i = i / 10;
        }
        System.out.println (i);
    }

    public static void main5 (String[] args) {
        Scanner p = new Scanner (System.in);
        int t = 0;
        int i = 0, j = 0;
        System.out.print ("请输入数字：");
        int l = p.nextInt ();
        for (i = 0; i < l; i++) {
            for (j = 0; j < l; j++) {
                if (j == t || j == l - t - 1) {
                    System.out.print ("*");
                } else System.out.print (" ");
            }
            t++;
            System.out.println ();
        }

    }

    public static void main4 (String[] args) {
        Random ran = new Random ();
        int ra = ran.nextInt (101);//一个左闭右开的随机数
        Scanner sca = new Scanner (System.in);
        System.out.print ("请输入要猜的数字：");
        while (true) {
            int a = sca.nextInt ();
            if (a == ra) {
                System.out.println ("猜对了");
                break;
            } else if (a < ra) {
                System.out.println ("猜小了");
            } else if (a > ra) {
                System.out.println ("猜大了");
            }

        }
    }

    public static void main3 (String[] args) {
        Scanner sa = new Scanner (System.in);
        System.out.println ("请输入数字");
        int a = sa.nextInt ();

        String d = sa.nextLine ();
        System.out.println ("请输入名字");
        //String b=sa.nextLine ();//nextLine方法是读取一行的所有字符串，包含空格
        String b = sa.next ();//line方法只会读取到空格处的字符串

        System.out.println (a);
        System.out.println (b);
    }

    public static void main2 (String[] args) {
        double i = 0.0;
        double t = - 1.0;
        double sum = 0.0;
        double m = 0.0;
        for (i = 1; i <= 100; i++) {
            t = - 1 * t;
            m = 1 / i;
            sum = t * m + sum;
        }
        System.out.println (sum);
    }

    public static void main1 (String[] args) {
        int i = 1, num = 0;
        for (; i < 100; i++) {
            if (i / 10 == 9) num++;
            if (i % 10 == 9) num++;
        }
        num = num - 1;
        System.out.println (num);
    }
}
